<template>
	<view>
		<view class="form-flex" id="top-box">
			<text class="form-title">部门：</text>
			<picker :value="branchIndex" :range="branchArray" @change="bindPickerChange" style="width: 60%;">
				<view id="branch" class="column-middle">
					<text>{{branchArray[branchIndex]}}</text>
					<image class="branch-icon" src="/static/corporation/turnDown.png"></image>
				</view>
			</picker>
		</view>
		<view class="form-flex">
			<text class="form-title">姓名：</text>
			<input class="form-input" placeholder="请输入姓名" v-model="trueName" />
		</view>
		<view class="form-flex">
			<text class="form-title">班级：</text>
			<input class="form-input" placeholder="请输入专业班级" v-model="major" />
		</view>
		<view class="width-90 flex-column">
			<text class="form-title" style="width: 30%;">简介/说明：</text>
			<view class="cu-form-group" >
				<textarea maxlength="120" placeholder="简单介绍一下自己..." id="textarea-height" v-model="content"></textarea>
			</view>
			<button class="common-button" @click="applyCorporation()">提交</button>
		</view>
	</view>
</template>

<script>
	import {
		applyCorporation
	} from '@/common/api/corporation/corporationMember.js'
	import judge from '@/common/utils/judgement.js'
	export default {
		data() {
			return {
				branchIndex: 0,
				branchArray: ['会员','组织部','宣传部','外联部','技术部','秘书部'],
				content: '',
				major: '',
				trueName: ''
			}
		},
		methods: {
			// 选择部门
			bindPickerChange:function(e){
				this.branchIndex = e.detail.value
			},
			// 加入社团
			applyCorporation:function(){
				if(judge(this.content) && judge(this.major) && judge(this.trueName)) {
					applyCorporation({
						clubId: uni.getStorageSync("clubId"),
						content: this.content,
						department: this.branchArray[this.branchIndex],
						major: this.major,
						memberId: uni.getStorageSync("memberId"),
						trueName: this.trueName
					}).then(res => {
						if(res.data.code == 200) {
							if(res.data.data == true) {
								uni.showToast({
									title: "申请成功",
									icon: 'none'
								})
								uni.setStorageSync("isApply",true)
								uni.reLaunch({
									url: '/pages/corporation/corporation'
								})
							}
							
						} else {
							uni.showToast({
								title: "网络错误",
								icon: 'none'
							})
						}
					})
				} else {
					uni.showToast({
						title: "输入值不能为空",
						icon: 'none'
					})
				}
				
			},
		}
	}
</script>

<style>
#top-box{
	margin-top: 50rpx;
}
#textarea-height{
	width: 90%;
	height: 250rpx;
	border: 1px solid #E8E8E8;
	border-radius: 7px;
	padding: 20rpx;
}
</style>
